﻿#pragma once
#include <QObject>
#include <QJsonObject>

class ConfigHelper: public QObject {
	Q_OBJECT
	Q_PROPERTY(int firstScreen READ firstScreen CONSTANT)
	Q_PROPERTY(int secondScreen READ secondScreen CONSTANT)
	Q_PROPERTY(QJsonObject rootObject READ rootObject CONSTANT)
	Q_PROPERTY(double m5Speed READ m5Speed WRITE setM5Speed NOTIFY m5SpeedChanged)
	Q_PROPERTY(double m6Speed READ m6Speed WRITE setM6Speed NOTIFY m6SpeedChanged)
	Q_PROPERTY(double m4RotSpeed READ m4RotSpeed WRITE setM4RotSpeed NOTIFY m4RotSpeedChanged)
	Q_PROPERTY(double m7Speed READ m7Speed WRITE setM7Speed NOTIFY m7SpeedChanged)
	Q_PROPERTY(double m2Speed READ m2Speed WRITE setM2Speed NOTIFY m2SpeedChanged)
	Q_PROPERTY(double m3RotSpeed READ m3RotSpeed WRITE setM3RotSpeed NOTIFY m3RotSpeedChanged)
	Q_PROPERTY(double m11Speed READ m11Speed WRITE setM11Speed NOTIFY m11SpeedChanged)
	Q_PROPERTY(double m1RotSpeed READ m1RotSpeed WRITE setM1RotSpeed NOTIFY m1RotSpeedChanged)
	Q_PROPERTY(double m13Speed READ m13Speed WRITE setM13Speed NOTIFY m13SpeedChanged)
	Q_PROPERTY(double m14Speed READ m14Speed WRITE setM14Speed NOTIFY m14SpeedChanged)
	Q_PROPERTY(double m12Speed READ m12Speed WRITE setM12Speed NOTIFY m12SpeedChanged)
	Q_PROPERTY(double m08Speed READ m08Speed WRITE setM08Speed NOTIFY m08SpeedChanged)
	Q_PROPERTY(double enc2Min READ enc2Min WRITE setEnc2Min NOTIFY enc2MinChanged)
	Q_PROPERTY(double enc2Max READ enc2Max WRITE setEnc2Max NOTIFY enc2MaxChanged)
	Q_PROPERTY(double m1413Speed READ m1413Speed WRITE setM1413Speed NOTIFY m1413SpeedChanged)
	Q_PROPERTY(double enc3Min READ enc3Min WRITE setEnc3Min NOTIFY enc3MinChanged)
	Q_PROPERTY(double enc3Max READ enc3Max WRITE setEnc3Max NOTIFY enc3MaxChanged)
public:
	ConfigHelper(QString const& fileName, QObject* parent = nullptr);
	~ConfigHelper();
	QJsonObject rootObject() const;
	double m1413Speed() const;
	void setM1413Speed(double value);
	double enc3Min() const;
	void setEnc3Min(double value);
	double enc3Max() const;
	void setEnc3Max(double value);
	int firstScreen() const;
	int secondScreen() const;
	double m5Speed() const;
	void setM5Speed(double value);
	double m6Speed() const;
	void setM6Speed(double value);
	double m4RotSpeed() const;
	void setM4RotSpeed(double value);
	double m7Speed() const;
	void setM7Speed(double value);
	double m2Speed() const;
	void setM2Speed(double value);
	double m3RotSpeed() const;
	void setM3RotSpeed(double value);
	double m11Speed() const;
	void setM11Speed(double value);
	double m1RotSpeed() const;
	void setM1RotSpeed(double value);
	double m13Speed() const;
	void setM13Speed(double value);
	double m14Speed() const;
	void setM14Speed(double value);
	double m12Speed() const;
	void setM12Speed(double value);
	double m08Speed() const;
	void setM08Speed(double value);	
	double enc2Min() const;
	void setEnc2Min(double value);
	double enc2Max() const;
	void setEnc2Max(double value);
	Q_INVOKABLE void reload();
	Q_INVOKABLE bool updateConfig(QJsonObject const& obj);
signals:
	void enc3MinChanged();
	void enc3MaxChanged();
	void m1413SpeedChanged();
	void m5SpeedChanged();
	void m6SpeedChanged();
	void m4RotSpeedChanged();
	void m7SpeedChanged();
	void m2SpeedChanged();
	void m3RotSpeedChanged();
	void m11SpeedChanged();
	void m1RotSpeedChanged();
	void m13SpeedChanged();
	void m14SpeedChanged();
	void m12SpeedChanged();
	void m08SpeedChanged();
	void enc2MinChanged();
	void enc2MaxChanged();
private:
	Q_DISABLE_COPY(ConfigHelper)

	QString m_fileName;
	QJsonObject m_root;
};
